import config from '../utils/config'

export default (url,data={},method='get') => {
    return new Promise((resolve,reject) => {
        wx.request({
            url:config.host + url,data,method,
            header:{
                // 即使为空字符又或者不存在cookies这个键,也给它一个空字符串
                cookie:wx.getStorageSync('cookies') ? wx.getStorageSync('cookies') :""
            },
            success:(res)=>{
                // console.log(data);
                // console.log(res);
                // console.log(res.cookies);
                if(data.isLogin){
                    res.cookies.forEach(item=>{
                        // console.log(item);
                        if(item.includes("MUSIC_U")){
                            // console.log(item.includes("MUSIC_U"));
                            // console.log(item);
                            wx.setStorage({key:'cookies', data:item})
                        }
                    })      
                }
                resolve(res)
            },
            fail:(err)=>{
                reject(err)
            }
        })
    })

}